package com.onenine.app.listener;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.callback.ItemDragAndSwipeCallback;

/**
 * 最后项不参与拖拽Callback
 * 常用于添加图片最后一项为加号
 */
public class LastItemUnDragAndSwipeCallback extends ItemDragAndSwipeCallback {

    private ItemTouchHelper mItemTouchHelper;

    public LastItemUnDragAndSwipeCallback(RecyclerView recyclerView, BaseItemDraggableAdapter adapter) {
        super(adapter);
        mItemTouchHelper = new ItemTouchHelper(this);
        mItemTouchHelper.attachToRecyclerView(recyclerView);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
        int count = recyclerView.getChildCount();
        if (source.getAdapterPosition() == count - 1
                || target.getAdapterPosition() == count - 1) {
            return false;
        }
        return super.onMove(recyclerView, source, target);
    }

    public ItemTouchHelper getItemTouchHelper() {
        return mItemTouchHelper;
    }

}
